function [PQ, track_id, priority] = PQ_Fetch_Task(PQ, mode)
%PQ_Fetch_Task Summary of this function goes here
%   Detailed explanation goes here
  if PQ_Size(PQ) > 0
    switch mode
      case 1 % priority ordering
        track_id = PQ(1, 1);
        priority = PQ(1, 2);

        PQ = PQ(2:end, :);
      case 2 % random access
        idx = randi([1 PQ_Size(PQ)], 1);

        track_id = PQ(idx, 1);
        priority = PQ(idx, 2);

        PQ = [PQ(1:idx-1,:); PQ(idx+1:end,:)];
    end
  else
    track_id = 0;
    priority = -1;
  end
end